有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

io是输入流。close()是java中的阻塞调用吗?

我试着从一个输入到另一个输入,一块一块地读。close(); 但是,main的执行被阻止。出路是什么

根据建议,我使用的代码是

if (!processed) {
                System.out.println("in processed");
                byte[] contents = new byte[(int) fileSplit.getLength()];
                Path file = fileSplit.getPath();
                FileSystem fs = file.getFileSystem(conf);
                FSDataInputStream in = null;
                try {
                    in = fs.open(file);
                    IOUtils.readFully(in, contents, 0, contents.length);

                    value.set(contents, 0, contents.length);
                } finally {
                    System.out.println("before close stream");
                    IOUtils.closeStream(in);
                }
                processed = true;
                return true;
            }
            System.out.println("out of processed");
            return false;
        }

共 (1) 个答案

  1. # 1 楼答案

    爪哇。木卫一。输入流。close并没有阻塞,至少API从未说过这一点。比较 输入流。阅读

     Reads the next byte of data from the input stream. The value byte is
     returned as an <code>int</code> in the range <code>0</code> to
     <code>255</code>. If no byte is available because the end of the stream
     has been reached, the value <code>-1</code> is returned. This method
     blocks until input data is available, the end of the stream is detected,
     or an exception is thrown.
    

    和输入流。接近

      Closes this file input stream and releases any system resources
      associated with the stream.
    

    至于解决您的问题,我建议使用Java7文件。阅读所有字节,忘记你的谜题